package com.atguigu.ssyx.acl.service.impl;

import com.atguigu.ssyx.acl.mapper.AdminMapper;
import com.atguigu.ssyx.acl.service.AdminService;
import com.atguigu.ssyx.model.acl.Admin;
import com.atguigu.ssyx.model.acl.Role;
import com.atguigu.ssyx.vo.acl.AdminQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * ClassName: AdminServiceImpl
 * Package: com.atguigu.ssyx.acl.service.impl
 * Description:
 *
 * @Author Root
 * @Create 2023/9/6 8:51
 * @Version 1.0
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Override
    public IPage<Admin> selectPageUser(Page<Admin> pageParam, AdminQueryVo adminQueryVo) {
        //获取条件值
        String username = adminQueryVo.getUsername();
        String name = adminQueryVo.getName();
        //创建mp条件对象
        LambdaQueryWrapper<Admin> wrapper=new LambdaQueryWrapper<>();
        //判断条件值是否为空，不为空封装查询条件
        if(!StringUtils.isEmpty(name)){
            wrapper.like(Admin::getName, name);
        }
        if(!StringUtils.isEmpty(username)){
            wrapper.like(Admin::getUsername, username);
        }
        //调用方法实现条件分页查询
        Page<Admin> adminPage = baseMapper.selectPage(pageParam, wrapper);
        //返回分页对象
        return adminPage;
    }

}
